package com.xzk.util;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName AdminLoginInterceptor
 * @Description 登录拦截
 * @Author 0715-YuHao
 * @Date 2020/10/4 21:50
 * @Version 1.0
 */
public class AdminLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        if (uri.endsWith("login.do") || uri.endsWith("logout.do") || uri.endsWith("login2.do") || UserUtil.getAdminUserName(request.getSession()) != null) {
            return true;
        }
        response.sendRedirect("/admin/loginError.html");
        return false;
    }
}
